package com.zhongge;


import java.util.Stack;

/**
 * @ClassName MyQueue
 * @Description TODO
 * @Author zhongge
 * @Version 1.0
 */
public class MyQueue {
    Stack<Integer> stack1;//入队
    Stack<Integer> stack2;//出队
    public MyQueue() {
        stack1 = new Stack<>();
        stack2 = new Stack<>();
    }

    public void push(int x) {
        stack1.push(x);
    }

    public int pop() {
        if (stack2.isEmpty()) {
            if (!stack1.isEmpty()) {
                int size = stack1.size();
                while (size > 0) {
                    stack2.push(stack1.pop());
                    size--;
                }
                return stack2.pop();
            }else {
                return -1;
            }
        }else {
            return stack2.pop();
        }
    }

    public int peek() {
        if (stack2.isEmpty()) {
            if (!stack1.isEmpty()) {
                int size = stack1.size();
                while (size > 0) {
                    stack2.push(stack1.pop());
                    size--;
                }
                return stack2.peek();
            }else {
                return -1;
            }
        }else {
            return stack2.peek();
        }
    }

    public boolean empty() {
        if (stack1.isEmpty() && stack2.isEmpty()) {
            return true;
        }
        return false;
    }
}
